package com.ss.android.article.base.feature.detail2.widget;

import android.content.Context;
import android.content.SharedPreferences;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bytedance.common.utility.UIUtils;
import com.ss.android.account.e.MuteQuickClickListener;
import com.ss.android.article.base.app.AppData;
import com.ss.android.article.base.feature.video.IVideoController;
import com.ss.android.article.base.ui.AnimationImageView;
import com.ss.android.article.base.ui.ClickableImageView;
import com.ss.android.article.base.ui.Tab;
import com.ss.android.article.base.utils.a.SharedPreferenceUtils;
import com.ss.android.article.browser.R;
import com.ss.android.common.callback.CallbackCenter;

public class DetailToolBar extends LinearLayout {
    public ImageView mActionViewCommentIv;
    public TextView mActionCommentCountTv;
    public AnimationImageView mActionFavorIv;
    public View mActionCommentLayout;
    public ImageView mActionViewUp;
    public int mCommentCount;
    public boolean h;
    public Animation i;
    public Animation j;
    public Animation k;
    public Animation l;
    OnChildViewClickCallback onChildViewClickCallback;
    private Tab m;
    private View mViewCommentLayoutView;
    private TextView mWriteCommentLayoutTv;
    private ImageView mActionRepostIv;
    private ClickableImageView SharePlatformIv;
    private MuteQuickClickListener onClickListener;

    public DetailToolBar(Context context) {
        this(context, null);
    }

    public DetailToolBar(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        this.mCommentCount = 0;
        this.onClickListener = new MuteQuickClickListener() {

            public final void doOnClick(View view) {
                CallbackCenter.notifyCallback(IVideoController.STOP_END_COVER, new Object[0]);
                int id = view.getId();
                if (id == R.id.write_comment_layout) {
                    DetailToolBar.this.h = true;
                    if (DetailToolBar.this.onChildViewClickCallback != null) {
                        DetailToolBar.this.onChildViewClickCallback.onWriteCommentClick();
                    }
                } else if (id == R.id.action_favor) {
                    if (DetailToolBar.this.onChildViewClickCallback != null) {
                        DetailToolBar.this.onChildViewClickCallback.onFavorBtnClick();
                    }
                } else if (id == R.id.view_comment_layout) {
                    if (DetailToolBar.this.onChildViewClickCallback != null) {
                        DetailToolBar.this.onChildViewClickCallback.onCommentLayoutClick();
                    }
                } else if (id == R.id.action_repost) {
                    if (DetailToolBar.this.onChildViewClickCallback != null) {
                        DetailToolBar.this.onChildViewClickCallback.onShare();
                    }
                } else if (id == R.id.iv_share_platform) {
                    if (DetailToolBar.this.onChildViewClickCallback != null) {
                        DetailToolBar.this.onChildViewClickCallback.onSharePlatformClick();
                    }
                } else if (id == R.id.layout_button_tab_previous && DetailToolBar.this.onChildViewClickCallback != null) {
                    DetailToolBar.this.onChildViewClickCallback.onBackClick();
                }
            }
        };
        this.i = new TranslateAnimation(0, 0f, 0, 0f, 1, 1f, 1, 0f);
        this.j = new TranslateAnimation(0, 0f, 0, 0f, 1, -1f, 1, 0f);
        this.k = new TranslateAnimation(0, 0f, 0, 0f, 1, 0f, 1, -1f);
        this.l = new TranslateAnimation(0, 0f, 0, 0f, 1, 0f, 1, 1f);
        DetailToolBar.inflate(this.getContext(), R.layout.new_tool_bar, ((ViewGroup) this));
        this.setPadding(0, 0, ((int) UIUtils.dp2px(this.getContext(), 15f)), 0);
        this.mActionCommentCountTv = this.findViewById(com.ss.android.article.browser.R.id.action_comment_count);
        this.mActionFavorIv = this.findViewById(com.ss.android.article.browser.R.id.action_favor);
        this.mActionFavorIv.setOnClickListener(this.onClickListener);
        this.mWriteCommentLayoutTv = this.findViewById(com.ss.android.article.browser.R.id.write_comment_layout);
        this.mWriteCommentLayoutTv.setOnClickListener(this.onClickListener);
        this.mWriteCommentLayoutTv.setText(AppData.getInstance().getWriteCommentHint());
        this.mViewCommentLayoutView = this.findViewById(com.ss.android.article.browser.R.id.view_comment_layout);
        this.mActionViewCommentIv = this.findViewById(com.ss.android.article.browser.R.id.action_view_comment);
        this.mViewCommentLayoutView.setOnClickListener(this.onClickListener);
        this.mActionRepostIv = this.findViewById(com.ss.android.article.browser.R.id.action_repost);
        this.mActionRepostIv.setOnClickListener(this.onClickListener);
        this.SharePlatformIv = this.findViewById(com.ss.android.article.browser.R.id.iv_share_platform);
        UIUtils.setVisibility(this.SharePlatformIv, 8);
        this.SharePlatformIv.setOnClickListener(this.onClickListener);
        this.m = new Tab("go_back", this.findViewById(com.ss.android.article.browser.R.id.layout_button_tab_previous));
        this.m.ivIcon.setImageResource(com.ss.android.article.browser.R.drawable.icon_arrow_previous_enabled);
        this.m.itemView.setOnClickListener(this.onClickListener);
        SharedPreferenceUtils.inst();
        this.setShareBtnDrawable(SharedPreferenceUtils.getInt("recent_share_way"));
        this.mActionCommentLayout = this.findViewById(com.ss.android.article.browser.R.id.action_commont_layout);
        this.mActionViewUp = this.findViewById(com.ss.android.article.browser.R.id.action_view_up);
        AppData.getInstance();
        boolean isNightMode = AppData.isNightMode();
        UIUtils.setBackgroundResource(this, R.drawable.detail_tool_bar_bg);
        UIUtils.setMaxLines(this.mActionCommentCountTv, R.drawable.gy);
        this.mActionCommentCountTv.setTextColor(this.getContext().getResources().getColor(com.ss.android.article.browser.R.color.a));
        this.mWriteCommentLayoutTv.setTextColor(this.getContext().getResources().getColorStateList(com.ss.android.article.browser.R.color.detail_action_write_comment_text));
        UIUtils.setMaxLines(this.mWriteCommentLayoutTv, R.drawable.bg_detail_comment_btn);
        this.mActionViewCommentIv.setImageResource(com.ss.android.article.browser.R.drawable.ic_action_comment);
        this.mActionRepostIv.setImageResource(com.ss.android.article.browser.R.drawable.ic_action_repost);
        this.mActionFavorIv.a(com.ss.android.article.browser.R.drawable.sf, R.drawable.se, isNightMode);
        this.mActionFavorIv.adaptNightMode(isNightMode);
        this.mActionViewUp.setImageResource(com.ss.android.article.browser.R.drawable.f3);
        this.i.setDuration(200);
        this.j.setDuration(200);
        this.k.setDuration(200);
        this.l.setDuration(200);
        this.i.setFillAfter(true);
        this.j.setFillAfter(true);
        this.k.setFillAfter(true);
        this.l.setFillAfter(true);
    }

    public final void saveShareWay(int sahreWay) {
        if ((AppData.getInstance().getAbSettings().isBottomShare()) && sahreWay >= 0) {
            SharedPreferenceUtils.inst();
            if (SharedPreferenceUtils.getInt("recent_share_way") != sahreWay) {
                this.setShareBtnDrawable(sahreWay);
                SharedPreferenceUtils.inst();
                SharedPreferences.Editor editor = SharedPreferenceUtils.getEditor("main_app_settings");
                editor.putInt("recent_share_way", sahreWay);
                editor.apply();
            }
        }
    }

    public final void setCommentCount(int commentCount) {
        if (commentCount > 0) {
            UIUtils.setLayoutMargins(this.mActionViewCommentIv, -3, -3, this.getResources().getDimensionPixelOffset(R.dimen.detail_tool_bar_comment_margin), -3);
            UIUtils.setVisibility(this.mActionCommentCountTv, 0);
            try {
                this.mActionCommentCountTv.setText(String.valueOf(commentCount));
                this.mCommentCount = commentCount;
            } catch (Throwable throwable) {
            }
        } else {
            UIUtils.setVisibility(this.mActionCommentCountTv, 8);
            UIUtils.setLayoutMargins(this.mActionViewCommentIv, -3, -3, 0, -3);
        }
    }

    public void setFavorIconSelected(boolean arg2) {
        this.mActionFavorIv.setSelected(arg2);
    }

    public void setOnChildViewClickCallback(OnChildViewClickCallback onChildViewClickCallback) {
        this.onChildViewClickCallback = onChildViewClickCallback;
    }

    private void setShareBtnDrawable(int sharePlatform) {
        int shareIconResId;
        if (AppData.getInstance().getAbSettings().isBottomShare()) {
            UIUtils.setVisibility(this.mActionRepostIv, 8);
            UIUtils.setVisibility(this.SharePlatformIv, 0);
            switch (sharePlatform) {
                case 1: {
                    shareIconResId = R.drawable.icon_moment;
                    break;
                }
                case 3: {
                    shareIconResId = R.drawable.icon_qq;
                    break;
                }
                default: {
                    shareIconResId = R.drawable.icon_wechat;
                    break;
                }
            }

            this.SharePlatformIv.setViewAlpha(0.7f);
            this.SharePlatformIv.setResource(shareIconResId);
        }
    }

    public void setToolBarStyle(DetailStyle detailStyle) {
        if (detailStyle == DetailStyle.NATIVE_PICGROUP_STYLE) {
            this.setBackgroundResource(com.ss.android.article.browser.R.color.trans_half_black);
        } else if (detailStyle == DetailStyle.WAP_PICGROUP_STYLE) {
            this.setBackgroundResource(com.ss.android.article.browser.R.color.transparent);
        } else {
            return;
        }
        this.m.ivIcon.setImageResource(com.ss.android.article.browser.R.drawable.picture_detail_comment_icon_bg);
        this.mWriteCommentLayoutTv.setTextColor(this.getContext().getResources().getColor(com.ss.android.article.browser.R.color.ssxinzi3));
        UIUtils.setBackgroundResource(this.mWriteCommentLayoutTv, R.drawable.picture_detail_page_comment_icon_tag_bg);
        this.mActionViewCommentIv.setImageResource(com.ss.android.article.browser.R.drawable.hd);
        this.mActionCommentCountTv.setTextColor(this.getContext().getResources().getColor(com.ss.android.article.browser.R.color.ssxinzi8));
        UIUtils.setBackgroundResource(this.mActionCommentCountTv, R.drawable.he);
        this.mActionFavorIv.a(com.ss.android.article.browser.R.drawable.icon_details_collect_press, R.drawable.icon_details_collect, false);
        this.mActionRepostIv.setImageResource(com.ss.android.article.browser.R.drawable.hh);

    }

    public void setWriteCommentEnabled(boolean enable) {
        this.mWriteCommentLayoutTv.setEnabled(enable);
    }

    public interface OnChildViewClickCallback {
        void onBackClick();

        void onSharePlatformClick();

        void onWriteCommentClick();

        void onFavorBtnClick();

        void onCommentLayoutClick();

        void onShare();
    }
}

